<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Purview_model extends Base_model {

    protected $_table_name = 'purview';
    protected $_key_name = 'purview_id';

    function get_info($id) {
        if (!empty($id))
            $where[$this->_key_name] = $id;
        $where["purview_dtime"] = 0;
        return $this->fetch(NULL, $where, NULL, 'row');
    }

    function get_all() {
        $this->db->join('system_module', 'purview.system_module_id = system_module.system_module_id');
        $where["purview.dtime"] = 0;
        return $this->fetch(NULL, $where);
    }

    function get_purview() {
        $where["purview.dtime"] = 0;
        $result = $this->fetch(NULL, $where);
        $p = array();
        foreach ($result as $key => $val) {
            $p[$val->system_module_id][$val->purview_id] = $val;
        }
        return $p;
    }

    function query_keyword($keyword = "", $limit) {
        $this->set_or_like('name,mark,description', $keyword);
        $this->set_limit($limit);
        $where["dtime"] = 0;
        return $this->fetch(NULL, $where);
    }

    function query_keyword_count($keyword = null) {
        $this->set_or_like('name,mark,description', $keyword);
        $con["where"][] = array("dtime" => 0);
        $this->set_args_array($con);
        return $this->fetch_count();
    }

    function update_data($data) {
        $value = array('system_module_id' => $data['system_module_id'], 'name' => $data['name'], 'mark' => $data['mark'], 'description' => $data['description'], 'mtime' => time());
        $where[] = array($this->_key_name => $data['id']);
        return $this->update($value, $where);
    }

    function add($data) {
        $data["ctime"] = time();
        return $this->insert($data);
    }

    function del($data) {
        $where = array($this->_key_name => $data['id']);
        $value = array("dtime" => time());
        return $this->update($value, $where);
    }

}
